﻿'© 2004 - 2009 ActiveModules, Inc. All Rights Reserved
Imports Microsoft.ApplicationBlocks.Data
Imports System.Xml
Namespace DotNetNuke.Modules.ActiveForums.Data
    Public Class Topics
        Inherits DataConfig
        Public Function Reply_Save(ByVal ri As ReplyInfo) As Integer
            Return CType(Reply_Save(ri.TopicId, ri.ReplyId, ri.ReplyToId, ri.StatusId, ri.IsApproved, ri.IsDeleted, ri.Content.Subject.Trim, ri.Content.Body.Trim, ri.Content.DateCreated, ri.Content.DateUpdated, ri.Content.AuthorId, ri.Content.AuthorName, ri.Content.IPAddress), Integer)
        End Function
        Public Function Reply_Save(ByVal TopicId As Integer, ByVal ReplyId As Integer, ByVal ReplyToId As Integer, ByVal StatusId As Integer, ByVal IsApproved As Boolean, ByVal IsDeleted As Boolean, ByVal Subject As String, ByVal Body As String, ByVal DateCreated As Date, ByVal DateUpdated As Date, ByVal AuthorId As Integer, ByVal AuthorName As String, ByVal IPAddress As String) As Integer
            Return CType(SqlHelper.ExecuteScalar(_connectionString, dbPrefix & "Reply_Save", TopicId, ReplyId, ReplyToId, StatusId, IsApproved, IsDeleted, Subject, Body, DateCreated, DateUpdated, AuthorId, AuthorName, IPAddress), Integer)
        End Function
        Public Function TopicIdByUrl(ByVal PortalId As Integer, ByVal ModuleId As Integer, ByVal URL As String) As Integer
            If URL.EndsWith("/") Then
                URL = URL.Substring(0, URL.Length - 1)
            End If
            Return CType(SqlHelper.ExecuteScalar(_connectionString, dbPrefix & "TopicIdByURL", PortalId, ModuleId, URL), Integer)
        End Function
        Public Function Topics_AddRating(ByVal TopicId As Integer, ByVal UserID As Integer, ByVal Rating As Integer, ByVal Comments As String, ByVal IPAddress As String) As Integer
            Return CType(SqlHelper.ExecuteScalar(_connectionString, dbPrefix & "Topics_AddRating", TopicId, UserID, Rating, Comments, IPAddress), Integer)
        End Function
        Public Function TopicForDisplay(ByVal SiteId As Integer, ByVal InstanceId As Integer, ByVal ForumId As Integer, ByVal TopicId As Integer, ByVal UserId As Integer, ByVal RowIndex As Integer, ByVal MaxRows As Integer, ByVal Sort As String) As IDataReader
            Dim dr As IDataReader = SqlHelper.ExecuteReader(_connectionString, dbPrefix & "UI_TopicDisplay", SiteId, InstanceId, ForumId, TopicId, UserId, RowIndex, MaxRows, False, Sort)
            Return dr
        End Function
        Public Function TopicsList(ByVal PortalId As Integer, ByVal PageIndex As Integer, ByVal PageSize As Integer, ByVal ForumIds As String, ByVal CategoryId As Integer, ByVal TagId As Integer) As IDataReader
            Return SqlHelper.ExecuteReader(_connectionString, dbPrefix & "TopicsList", PortalId, PageIndex, PageSize, ForumIds, CategoryId, TagId)
        End Function
        Public Function TopicWithReplies(ByVal PortalId As Integer, ByVal TopicId As Integer, ByVal PageIndex As Integer, ByVal PageSize As Integer) As IDataReader
            Return SqlHelper.ExecuteReader(_connectionString, dbPrefix & "TopicWithReplies", PortalId, TopicId, PageIndex, PageSize)
        End Function
        'Public Function TopicsForDisplayXML(ByVal SiteId As Integer, ByVal InstanceId As Integer, ByVal ForumId As Integer, ByVal UserId As Integer, ByVal PageIndex As Integer, ByVal PageSize As Integer, ByVal IsSuper As Boolean, ByVal SortColumn As String, ByVal ForumIds As String) As XmlDocument
        '    Dim dr As IDataReader = SqlHelper.ExecuteReader(_connectionString, dbPrefix & "UI_TopicsDisplay", SiteId, InstanceId, ForumId, UserId, PageIndex, PageSize, IsSuper, SortColumn, ForumIds)
        '    Dim sb As New Text.StringBuilder
        '    sb.Append("<?xml version=""1.0"" encoding=""utf-8"" ?>")
        '    sb.Append("<root><topics>")
        '    While dr.Read()
        '        sb.Append("<topic forumid=""" & dr("ForumId").ToString & """ ")
        '        sb.Append("topicid=""" & dr("TopicId").ToString & """ ")
        '        sb.Append("lastreplyid=""" & dr("lastreplyid").ToString & """ ")
        '        sb.Append("viewcount=""" & dr("viewcount").ToString & """ ")
        '        sb.Append("replycount=""" & dr("replycount").ToString & """ ")
        '        sb.Append("islocked=""" & dr("islocked").ToString & """ ")
        '        sb.Append("ispinned=""" & dr("ispinned").ToString & """ ")
        '        sb.Append("topicicon=""" & dr("topicicon").ToString & """ ")
        '        sb.Append("statusid=""" & dr("statusid").ToString & """ ")
        '        sb.Append("isannounce=""" & dr("isannounce").ToString & """ ")
        '        sb.Append("announcestart=""" & dr("announcestart").ToString & """ ")
        '        sb.Append("announceend=""" & dr("announceend").ToString & """ ")
        '        sb.Append("topictype=""" & dr("TopicType").ToString & """ ")
        '        sb.Append("authorid=""" & dr("authorid").ToString & """ ")
        '        sb.Append("datecreated=""" & dr("datecreated").ToString & """ ")
        '        sb.Append("lastpostdate=""" & dr("lastpostdate").ToString & """ ")
        '        sb.Append("userlastreplyread=""" & dr("userlastreplyread").ToString & """ ")
        '        sb.Append("userlasttopicread=""" & dr("userlasttopicread").ToString & """ ")
        '        sb.Append("topicrating=""" & dr("topicrating").ToString & """>")
        '        sb.Append("<subject><![CDATA[" & dr("subject").ToString & "]]></subject>")
        '        sb.Append("<summary><![CDATA[" & dr("summary").ToString & "]]></summary>")
        '        sb.Append("<body><![CDATA[" & dr("body").ToString & "]]></body>")
        '        sb.Append("<authorname><![CDATA[" & dr("authorname").ToString & "]]></authorname>")
        '        sb.Append("<username><![CDATA[" & dr("username").ToString & "]]></username>")
        '        sb.Append("<firstname><![CDATA[" & dr("firstname").ToString & "]]></firstname>")
        '        sb.Append("<lastname><![CDATA[" & dr("lastname").ToString & "]]></lastname>")
        '        sb.Append("<displayname><![CDATA[" & dr("displayname").ToString & "]]></displayname>")
        '        sb.Append("<forumname><![CDATA[" & dr("forumname").ToString & "]]></forumname>")
        '        sb.Append("<groupname><![CDATA[" & dr("groupname").ToString & "]]></groupname>")
        '        sb.Append("<security>")
        '        sb.Append("<view>" & dr("CanView").ToString & "</view>")
        '        sb.Append("<read>" & dr("CanRead").ToString & "</read>")
        '        sb.Append("<create>" & dr("CanCreate").ToString & "</create>")
        '        sb.Append("<reply>" & dr("CanEdit").ToString & "</reply>")
        '        sb.Append("<edit>" & dr("CanEdit").ToString & "</edit>")
        '        sb.Append("<delete>" & dr("CanDelete").ToString & "</delete>")
        '        sb.Append("<lock>" & dr("CanLock").ToString & "</lock>")
        '        sb.Append("<pin>" & dr("CanPin").ToString & "</pin>")
        '        sb.Append("<modapprove>" & dr("Canmodapprove").ToString & "</modapprove>")
        '        sb.Append("<modedit>" & dr("canmodedit").ToString & "</modedit>")
        '        sb.Append("<moddelete>" & dr("canmoddelete").ToString & "</moddelete>")
        '        sb.Append("<modlock>" & dr("canmodlock").ToString & "</modlock>")
        '        sb.Append("<modpin>" & dr("canmodpin").ToString & "</modpin>")
        '        sb.Append("<modmove>" & dr("canmodmove").ToString & "</modmove>")
        '        sb.Append("</security>")
        '        sb.Append(dr("lastpostdata").ToString)
        '        sb.Append("</topic>")


        '    End While
        '    sb.Append("</topics></root>")
        '    dr.Close()
        '    Dim xDoc As New XmlDocument
        '    xDoc.LoadXml(sb.ToString)
        '    Return xDoc
        'End Function
    End Class
End Namespace
